package com.zhiyou100.JDBCUtil;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
    private static DataSource pool;

    static {
        Properties pro = new Properties();
        InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("db.properties");
        try {
            pro.load(is);
            pool = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static DataSource getDataSource() {
        return DBUtil.pool;
    }

    public static Connection getConnection() {
        try {
            return pool.getConnection();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    /*public static void main(String[] args) {
        System.out.println(getDataSource());
        System.out.println(getConnection());
    }*/
}


